
<#
  @brief  正则式快速修改DellSC存储卷名称
  @Notes  None.
  @param  $StorageIP, Dell Storage Center IP地址
  @param  $LoginUser, 用户名
  @param  $StorageSN, Dell Storage Center序列号
  @param  $MatchStr, 需要匹配的字符串
  @param  $RegPosition, 正则匹配位置
  @retval "success"
#>
function ChangeVolumeName([string]$StorageIP, [string]$LoginUser, [int]$StorageSN, [string]$MatchStr, [int]$RegPosition)
{
    $conn = Connect-DellApiConnection -HostName $StorageIP -User $LoginUser
    $sc = Get-DellStorageCenter -Connection $conn -SerialNumber $StorageSN
    $scVolume = Get-DellScVolume -Connection $conn -StorageCenter $sc
    [regex]$pattern = $MatchStr
    ############  定义正则式 ################ 
    [string]$RegEX = "^" + $MatchStr + ".*";
    ########################################
    Foreach ( $disk in $scVolume )
    {
        if ( $disk.Name -match $RegEX )
        { 
            $OrigDiskName = $disk.Name
            $NewDiskName = $pattern.Replace($OrigDiskName,"", $RegPosition)
            Write-Host "Original Volume Name:" $OrigDiskName 
            Write-Host "New Volume Name:" $NewDiskName
            ## 修改卷名称操作 ->>
            #Set-DellScVolume -Connection $conn  -Instance $disk -Name $NewDiskName
        }
    }  
    return "success"
}

###############  函数测试 ###################
$RSTVAR = ChangeVolumeName "172.24.1.xxx" "Admin" xxxxx "LV of " 1
Write-Host $RSTVAR